package com.giser.testapp.lib.Push;

import android.app.ActivityManager;
import android.app.ActivityManager.RunningTaskInfo;
import android.content.ComponentName;
import android.content.Context;

import com.giser.testapp.lib.App.GlobClass;

import java.util.List;

/**
 * Created by Lss on 2017/12/7.
 */

public class GlobCheck {
    public static boolean CheckProgressIsRunning(Context context, String packageName){
        ActivityManager activityManager = (ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE);
        List<RunningTaskInfo> list = activityManager.getRunningTasks(100);

        boolean isStart=false;
        for (RunningTaskInfo info : list) {
            if (info.topActivity.getPackageName().equals(packageName) ||  info.baseActivity.getPackageName().equals(packageName)) {
                isStart=true;
                break;
            }
        }
        return isStart;
    }

    public static String getCurrentPackageName(Context context){
        ActivityManager am = (ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE);
        ComponentName cn = am.getRunningTasks(1).get(0).topActivity;
        String packageName = cn.getPackageName();
        return packageName;
    }

    public static String getMySystemName(Context context){
        ActivityManager activityManager = (ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE);
        List<RunningTaskInfo> list = activityManager.getRunningTasks(100);
        String className = "";
        for (int i = 0; i < list.size(); i++)
        {
            if (GlobClass.PackageName.equals(list.get(i).topActivity.getPackageName()))
            {
                className = list.get(i).topActivity.getClassName();
                return className;
            }
        }
        return className;
    }

    /*public static void goToSetNotify(){
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.BASE) {
            // 进入设置系统应用权限界面
            Intent intent = new Intent(Settings.ACTION_SETTINGS);
            startActivity(intent);
            return;
        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {// 运行系统在5.x环境使用
            // 进入设置系统应用权限界面
            Intent intent = new Intent(Settings.ACTION_SETTINGS);
            startActivity(intent);
            return;
        }
    }*/
}
